#ifndef EVENT_H
#define EVENT_H

#ifdef HAVE_EPOLL
#include <sys/epoll.h>
#elif HAVE_KQUEUE
#include <sys/event.h>
#elif HAVE_PORT
#include <port.h>
#endif

#include "http_connection.h"

#define EVENT_IN  0x001
#define EVENT_OUT 0x004
#define EVENT_ERR 0x008
#define EVENT_HUP 0x010

#ifdef HAVE_EPOLL
typedef struct epoll_event event_t;

#define GET_FD(events, idx) (events[(idx)].data.fd)
#define GET_EVENT(event)    ((event)->events)
#elif HAVE_KQUEUE
#define NO_FILTER    (0)
#define FILTER_READ  (-1)
#define FILTER_WRITE (-2)

typedef struct kevent event_t;

#define GET_FD(events, idx) (events[(idx)].ident)
int GET_EVENT (event_t *event);
#elif HAVE_PORT
#define NO_FILTER    (0)
#define FILTER_READ  (-1)
#define FILTER_WRITE (-2)

typedef port_event_t event_t;

#define GET_FD(events, idx) ((int) events[(idx)].portev_object)
#define GET_EVENT(event)    ((event)->portev_events)
#endif

typedef int (*create_event_manager) (int size);

typedef int (*add_fd) (int fd, int events);
typedef int (*del_fd) (http_connection_t *http_connection);

typedef int (*del_listener) (int fd);

typedef int (*event_wait) (int timeout);

typedef int (*prepare_for_reading) (http_connection_t *http_connection);
typedef int (*prepare_for_writing) (http_connection_t *http_connection);
typedef int (*remove_notifications) (http_connection_t *http_connection);

#endif /* EVENT_H */
